home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / FULLPATH.C < prev    next >
Text File  |  1992-05-30  |  3KB  |  107 lines

  1. /********************************/
  2. /* File: FullPathName.c            */
  3. /*                                */
  4. /* Given the name and working    */
  5. /* directory of a file, walk the*/
  6. /* directory tree to determine    */
  7. /* what the full pathname of the*/
  8. /* directory is...                */
  9. /*                                */
  10. /* Paramters:                    */
  11. /* param0 = file name    num        */
  12. /* param1 = directory id         */
  13. /*                                */
  14. /* Out:                            */
  15. /* full pathname of the working    */
  16. /* directory                     */
  17. /* ----------------------------    */
  18. /* Once again, I am indepbted to*/
  19. /* Steve Maller of Apple         */
  20. /* Computer Inc for illuminating*/
  21. /* this oft too dark realm of     */
  22. /* the toolbox.                    */
  23. /********************************/
  24.  
  25. #include    <MacTypes.h>
  26. #include    <OSUtil.h>
  27. #include    <MemoryMgr.h>
  28. #include    <FileMgr.h>
  29. #include    <ResourceMgr.h>
  30. #include    <pascal.h>
  31. #include    <strings.h>
  32. #include    <hfs.h>
  33. #include     "HyperXCmd.h"
  34. #include    "HyperUtils.h"
  35.  
  36. #define        nil    0L
  37.  
  38. char        colon[2] = "\p:";
  39.  
  40.  
  41. pascal void main( paramPtr )
  42.     XCmdBlockPtr    paramPtr;
  43. {
  44.     Str31            str,fName;
  45.     short            wdid;
  46.     WDPBRec            theWDPB;
  47.     CInfoPBRec        theCPB;
  48.     HParamBlockRec    theHPB;
  49.     char            fullPath[256];
  50.     char            part_Name[256]; /*** used in HPB    ***/
  51.     char            vol_Name[256];
  52.     OSErr            err;
  53.  
  54.     colon[0] = 1;
  55.     colon[1] = ':';
  56.     
  57.     vol_Name[0] = '\0';
  58.     part_Name[0]= '\0';
  59.     /*** empty is the default answer ***/
  60.     paramPtr->returnValue = 0L;
  61.  
  62.     HLock( paramPtr->params[0] );
  63.     ZeroToPas( paramPtr, *(paramPtr->params[0]), &fName );
  64.     HUnlock( paramPtr->params[0] );
  65.     
  66.     /*** convert the wdid to a usable form ***/
  67.     HLock( paramPtr->params[1] );
  68.     ZeroToPas( paramPtr, *(paramPtr->params[1]), &str );
  69.     HUnlock( paramPtr->params[1] );
  70.     wdid = StrToNum( paramPtr, &str );
  71.     
  72.     /*** First, we appeal to GetVInfo to get    ***/
  73.     /*** the volume name that the file lives on    ***/
  74.     part_Name[0]         = '\0';                
  75.     theHPB.volumeParam.ioNamePtr    = (StringPtr)vol_Name;     
  76.     theHPB.volumeParam.ioVRefNum     = (short)wdid;         
  77.     theHPB.volumeParam.ioVolIndex     = 0;                 
  78.     if(PBHGetVInfo( &theHPB, 0) != noErr )
  79.         return;     
  80.  
  81.     /*** Next, use the working directory info    ***/
  82.     /*** to walk the directory tree backwards     ***/
  83.     /*** to the root directory                    ***/
  84.     theWDPB.ioNamePtr    = (StringPtr)part_Name;
  85.     theWDPB.ioVRefNum     = wdid;         
  86.     theWDPB.ioWDProcID    = 0;             
  87.     theWDPB.ioWDIndex     = 0;             
  88.     if( PBGetWDInfo( &theWDPB, 0) != noErr )     
  89.         return;
  90.     
  91.     fullPath[0] = '\0'; 
  92.     theCPB.dirInfo.ioFDirIndex = -1; 
  93.     theCPB.dirInfo.ioVRefNum    = theHPB.volumeParam.ioVRefNum;        
  94.  
  95.     ClimbTree(    theWDPB.ioWDDirID, 
  96.                 (CInfoPBPtr)&theCPB, 
  97.                 (StringPtr)fullPath );
  98.     
  99.     /*** Climbing the tree yields the names of    ***/
  100.     /*** all the folders which we still need to ***/
  101.     /*** add the file's name to.                ***/
  102.     Concat( (char *)fullPath, (char *)&fName );
  103.  
  104.     paramPtr->returnValue = PasToZero( paramPtr, fullPath );
  105. }
  106.  
  107.